package com.jzm.modules.permission.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jzm.common.util.PageUtils;
import com.jzm.common.util.R;
import com.jzm.modules.permission.model.JzmUser;
import com.jzm.modules.permission.service.UserService;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@Controller
@RequestMapping("/permission/user")
public class UserController {

	@Autowired
	private UserService userService;

	@ApiOperation(value = "获取用户列表", notes = "")
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public R list() {
		//FIXME 此处需要分页
		List<JzmUser> list = userService.selectAll();
		PageUtils pageUtil = new PageUtils(list, list.size(), 10, 1);
		return R.ok().put("page", pageUtil);
	}
	
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String toList(){
		return "permission/userList";
	}

	@ApiOperation(value = "获取用户详细信息", notes = "根据url的id来获取用户详细信息")
	@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Integer")
	@RequestMapping(value = "/view/{id}", method = RequestMethod.GET)
	@ResponseBody
	public JzmUser view(@PathVariable Long id) {
		JzmUser user = new JzmUser();
		user.setId(id);
		return userService.selectByPrimaryKey(user);
	}
}
